package com.atguigu.mybatis021.utils;


import com.atguigu.mybatis021.pojo.Employee;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(name = "返回数据格式")
public class R<T> {
    @Schema(name = "状态码")
    private Integer code;
    @Schema(name = "提示信息")
    private String message;
    @Schema(name = "返回数据")
    private T data;

    public static <T> R<T> ok(T data) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage("ok");
        r.setData(null);
        return r;
    }
    public static <T> R<T> ok(){
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage("ok");
        r.setData(null);
        return r;
    }
    public static <T> R<T> ok(Integer code, String message) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
    public static <T> R<T> ok(Integer code, String message, T data) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }


    public static <T> R<T> error(int code, String message) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }

    public static <T> R<T> error(String message) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
    public static <T> R<T> error(String message, T data) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
    public static <T> R<T> error(Integer code ,String message, T data) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
















}
